<?php
/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: dzf_base_router.php 1911 2013-08-26 02:26:48Z laoguozhang $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class dzf_base_router extends dzf_base_class
{
	public $default_controller = 'index';
	public $default_action = 'index';
	public $controller = '';
	public $action = '';
	public $routes = array();

	public function __construct() {
		parent::__construct();
	}

	/**
	 * 解析c和a，c和a只能是字母
	 */
	public function parse() {
		$this->controller = isset($_GET['c']) && !empty($_GET['c']) && ctype_alpha($_GET['c']) ? $_GET['c'] : $this->default_controller;
		$this->action = isset($_GET['a']) && !empty($_GET['a']) && ctype_alpha($_GET['a']) ? $_GET['a'] : $this->default_action;
	}
	
	public function add($name, $value) {
		$this->routes[$name] = $value;
	}

	public function get($name) {
		return $this->routes[$name];
	}

	public function get_url($controller='index', $action='index', $params=array()) {
		$data['c'] = $controller;
		$data['a'] = $action;
		return http_build_query(array_merge($data, $params));
	}
}